import router from "@src/router";
import { storeBindingsBehavior } from "mobx-miniprogram-bindings";
import member from "@src/store/member";

Component({
  behaviors: [storeBindingsBehavior],
  storeBindings: [{
    store: member,
    fields: ['isMember']
  }],
  properties: {
    features: {
      type: Array,
      default: []
    },
    login: {
      type: Boolean,
      default: true
    }
  },
  data: {},
  lifetimes: {
    attached: function () {

    },
    detached: function () {

    }
  },
  methods: {
    handleViewFeature: function (e) {
      if (!this.data.login) {
        return;
      }
      let item = e.currentTarget.dataset.item;
      let entrancePath = item.entrancePath;
      let name = router.getRouterName(entrancePath);
      if (router.requireMemberPages.indexOf(name) !== -1 && !this.data.isMember) {
        wx.showModal({
          title: "提示",
          content: "请先成为会员，才能访问该页面",
          cancelText: "取消",
          confirmText: "开卡页面",
          success: (sm) => {
            if (sm.confirm) {
              router.push({ name: "indexChooseCard" })
            }
          }
        });
      } else {
        console.log('item.entrancePath', item.entrancePath)
        getApp().$router.push({
          path: item.entrancePath, fail: (e) => {
            console.info(e)
          }
        })
      }
    }
  }
})
